package  
{
	/**
   * ...
   * @author ivan
   */
  public class ModeCommand implements Command
  {
    
    public function ModeCommand(graphStage:GraphStage, mode:String) 
    {
      this.graphStage = graphStage;
      this.mode = mode;
      previousMode = graphStage.mode;
      redo();
    }
    
    public function undo():void
    {
      setMode(previousMode);
    }
    
    public function redo():void
    {
      setMode(mode);
    }
    
    private function setMode(m:String):void
    {
      switch (m)
      {
        case GraphStage.MODE_EDIT:
        {
          graphStage.selection.enabled = true;
          graphStage.edgeTool.enabled = false;
          graphStage.radioButtonEdit.selected = true;
        }; break;
        
        case GraphStage.MODE_NODE:
        {
          graphStage.selection.enabled = false;
          graphStage.edgeTool.enabled = false;
          graphStage.radioButtonNode.selected = true;
        }; break;
        
        case GraphStage.MODE_EDGE:
        {
          graphStage.selection.enabled = false;
          graphStage.edgeTool.enabled = true;
          graphStage.radioButtonEdge.selected = true;
        }; break;
      };
      
      graphStage.mode = m;
      
      trace("mode " + m + " selected.");
    }
    
    private var graphStage:GraphStage;
    private var mode:String;
    private var previousMode:String;
    
  }

}